export class SoundManager {
    private static _instance: SoundManager;
    public static get instance(): SoundManager {
        if (this._instance) { console.log("已完成过初始化"); return this._instance; }
        this._instance = new SoundManager();
        Laya.timer.frameLoop(1, SoundManager.instance, SoundManager.instance.updateEye);
        return this._instance;
    }
    private bgm: Laya.SoundChannel;

    /** 监视者
     * 检查背景音乐的时间是否正常
     * 不正常则情况音频重新播放
     */
    private updateEye() {
        if (this.bgm) {
            // console.log("当前播放时间=>", this.sound.position, "/", +this.sound.duration);
            if (this.bgm.duration && this.bgm.duration < 3) {
                this.stopBGM();

                console.log("时间不对");
                this.playBGM(); //重新播放
            }
        }
    }

    public playBGM(): void {
        this.bgm = Laya.SoundManager.playMusic("resources/Audio/audioBgm.mp3");
        console.log("播放背景音乐", this.bgm); 
    }
    public stopBGM() {
        Laya.SoundManager.stopMusic();
        this.bgm = undefined;
    }
}